from members.models import Member

from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.contrib.auth.models import User


from registration import signals
from registration.forms import RegistrationForm


from registration.backends.simple import SimpleBackend

class MyRegBackend(SimpleBackend):

    def register(self, request, **kwargs):


        """
        Create and immediately log in a new user.
        
        """
        username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
        user = User.objects.create_user(username, email, password)
            
        # felix's work
        member = user.get_profile()
        member.name = kwargs['name']
        member.save()
         
        # authenticate() always has to be called before login(), and
        # will return the user we just created.
        new_user = authenticate(username=username, password=password)
        login(request, new_user)
        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)
  	
        return new_user

	
     
     def post_registration_redirect(self, request, user):
        """
        After registration, redirect to the user's account page.
        
        """
        return ('http://127.0.0.1:8000', (), {})
